// pages/clazz/clazz.js
var service = require('./clazzservice.js');
var app = getApp();
Page({
  data: {
    userInfo: {},
    list: [],
    scrollTop: 0,
    scrollHeight: 0,
    showLoading: true,
  },
  onShareAppMessage: function () {
    return {
      title: '班级互动',
      path: '/page/clazz/clazz'
    }
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        console.info(res.windowHeight);
        console.info(res.screenHeight);
        that.setData({
          scrollHeight: res.windowHeight
        });
      }
    });
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function (userInfo) {
      //更新数据
      that.setData({
        userInfo: userInfo
      })
    });
    console.info(service)
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
    var that = this;
   service.getClassList(that);
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  bindDownLoad: function () {
    //   该方法绑定了页面滑动到底部的事件
    console.info("底部");
    var that = this;
    service.getClassList(that);
  },
  scroll: function (event) {
    //   该方法绑定了页面滚动时的事件，我这里记录了当前的position.y的值,为了请求数据之后把页面定位到这里来。
    console.info(event.detail.scrollTop);
    this.setData({
      scrollTop: event.detail.scrollTop
    });
  },
  refresh: function (event) {
    //   该方法绑定了页面滑动到顶部的事件，然后做上拉刷新
    console.info("顶部")
    this.setData({
      list: [],
      scrollTop: 0,
      showLoading: true,
    });
    service.getClassList(this);
  },
  classDetail: function (event) {
    wx.navigateTo({
      url: '/pages/logs/logs?classID='+event.currentTarget.id
    });
  },
  openInstance: function (event) {
    wx.navigateTo({
      url: '/pages/logs/logs?instanceItemId='+event.currentTarget.id
    });
  }
})